# include <bits/stdc++.h>
# define col (b2 - b1 + 1)
using namespace std;

char buf[1 << 18], *fs, *ft;
char ops[1 << 18], *opt = ops, *opt_end = ops + (1 << 18);

inline char getc() { 
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline void oall() { 
    fwrite(ops, 1, opt - ops, stdout);
    opt = ops;
}

inline void oendl() { 
    *(opt++) = '\n';
    if(opt == opt_end) oall();
}

inline void ochar(char x) { 
    *(opt++) = x;
    if(opt == opt_end) oall();
}

inline short gn() { 
    short k = 0, f = 1;
    char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}

short n, m, k, a1, a2, b1, b2, l;
char mp[1001][1001];

int main() { 
# ifndef LOCAL 
    freopen("lostmonkey.in", "r", stdin);
    freopen("lostmonkey.out", "w", stdout);
# else 
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
# endif
    n = gn(), m = gn(), k = gn();
    for(short i = 1; i <= k; i++) { 
        a1 = gn(), b1 = gn(), a2 = gn(), b2 = gn(), l = gn();
        for(short i = a1; i <= a2; i++) 
            memset(mp[i] + b1, l, col);
    }
    for(short i = 1; i <= n; i++) { 
        for(short j = 1; j <= m; j++) 
            ochar(mp[i][j] + 48);
        oendl();
    }
    oall();
    return 0;
}
